<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use Hyperf\DbConnection\Db;
use Hyperf\Redis\Redis;
use Hyperf\HttpServer\Contract\RequestInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Trait\ResponseMsg;
use App\Model\Normal;
use Hyperf\Di\Annotation\Inject;
use Util\Common;
use App\Controller\AbstractController;
use App\Model\Distributors;

class NormalController extends AbstractController
{
    use ResponseMsg;

    protected Redis $redis;
    protected Normal $normal;

    public function __construct()
    {
        $this->redis = container()->get(Redis::class);
        $this->normal = container()->get(Normal::class);
    }

    /**前端所需通用数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|RedisException
     */
    public function getNormal(): ResponseInterface
    {
        $normal = $this->normal->get_redis_array(Common::SET_WEB_NORMAL_WEN);//获取通用数据
        return $this->success($normal);
    }

    /**设置前端通用数据
     * @param RequestInterface $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function setNormal(RequestInterface $request):ResponseInterface{
        $key = "SET_WEB_NORMAL_WEN";
        $data = $request->post();
        $this->redis->set($key,json_encode($data));
        return $this->success();
    }



    /**前端所需通用数据
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|RedisException
     */
    public function getBank(): ResponseInterface
    {
        $key = "SET_WEB_NORMAL_BANK";
        $data['bank_code'] = $this->redis->get($key);
        return $this->success($data);
    }

    /**设置前端通用数据
     * @param RequestInterface $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function setBank(RequestInterface $request):ResponseInterface{
        $key = "SET_WEB_NORMAL_BANK";
        $data = $request->input('bank_code');
        $this->redis->set($key,$data);
        return $this->success();
    }
}
